package com.mmm.nlp;

import com.mmm.nlp.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Queue;

/**
 * Created with IntelliJ IDEA.
 * User: Zhendong
 * Date: 4/20/13
 * Time: 10:02 AM
 * To change this template use File | Settings | File Templates.
 */
@Component("builder")
public class SimpleTaggedTextBuilder
{
  @Autowired
  TextReader reader;
  @Autowired
  TextWriter writer;
  @Autowired
  TextTokenizer tokenizer;
  @Autowired
  LexiconMatcher matcher;

  public void build() throws Exception
  {
    String text;
    while (reader.canRead())
    {
      text = reader.read();
      Queue<Token> tokens = tokenizer.tokenize(text);
      while(!tokens.isEmpty())
      {
        Token token = tokens.poll();
        matcher.match(token);
        writer.write(token.toString());
      }
    }
    writer.flush();
  }

}
